//
//  IndexShopNavView.m
//  YunFu
//
//  Created by Bager on 2018/8/31.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "IndexShopNavView.h"

#import "IndexShopNavCell.h"

@implementation IndexShopNavView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = HexColor(0xf4f5f6);
        [self createView];
        [self createTitleView];
    }
    return self;
}

- (void)createTitleView
{
    UILabel *labelDown = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 45, 5, 90, 30)];
    labelDown.textAlignment = NSTextAlignmentCenter;
    labelDown.text = @"名店导航";
    labelDown.font = [UIFont systemFontOfSize:14];
    labelDown.backgroundColor = HexColor(0x2ea9f7);
    labelDown.layer.cornerRadius = 14;
    labelDown.layer.masksToBounds = YES;
    labelDown.adjustsFontSizeToFitWidth = YES;
    labelDown.textColor = [UIColor whiteColor];
    [self addSubview:labelDown];
}

- (void)createView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2 - 30) / 2.0, 80);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 10;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 10;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 10, 10, 10);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.shopCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kPublicMargin, 20, kScreenWidth - kPublicMargin * 2, 80 * 2 + 40)  collectionViewLayout:flowLayout];
    
    self.shopCollectionView.backgroundColor = [UIColor whiteColor];
    
    self.shopCollectionView.dataSource = self;
    
    self.shopCollectionView.delegate = self;
    
    [self.shopCollectionView registerClass:[IndexShopNavCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    
    self.shopCollectionView.layer.cornerRadius = 4;
    self.shopCollectionView.layer.masksToBounds = YES;
    
    [self addSubview:self.shopCollectionView];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    IndexShopNavCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    
    NSArray *imgArray = @[@"yf1-tg1",@"yf1-tg2",@"yf1-tg3",@"yf1-tg4"];
    NSArray *nameArray = @[@"特色餐饮",@"品牌服装",@"酒店住宿",@"休闲娱乐"];
    NSArray *detailArray = @[@"各地美食应有尽有",@"潮流大牌都在身边",@"干净卫生舒适安全",@"闲暇时光尽情享受"];
    NSArray *typeArray = @[@"钜优惠",@"有格调",@"性价比",@"去哪玩"];
    NSArray *colorArray = @[HexColor(0xee6c6a),HexColor(0x60c9f8),HexColor(0x44e39a),HexColor(0xf9b15f)];
    NSArray *bgColorArray = @[HexColor(0xfcf0f2),HexColor(0xeef8fc),HexColor(0xf5fefa),HexColor(0xfffaf4)];


    [cell.img setImage:[UIImage imageNamed:imgArray[indexPath.item]]];
    cell.name.text = nameArray[indexPath.item];
    cell.detail.text = detailArray[indexPath.item];
    cell.type.text = typeArray[indexPath.item];
    cell.backgroundColor = bgColorArray[indexPath.item];
    cell.type.backgroundColor = colorArray[indexPath.item];
    cell.name.textColor = colorArray[indexPath.item];

    cell.layer.masksToBounds = YES;
    cell.layer.cornerRadius = 4;
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
